global SSDIMed "/disk/agedisk4/medicare.work/miller-DUA50377/proj_ssdi"
* Settings
version 16
do "$SSDIMed/scripts/_auxiliary/_project_settings.do"








foreach y in tot_pmt died_adj{
use $SSDIMed/data/analysis/master_cohort_panel.dta, clear 
by bene_id (rfrnc_yr): keep if (rfrnc_yr > init_yr) & inrange(age_year_covstart_fill, 20, 62)
gisid covstart_month bene_id rfrnc_yr
gegen age_sex = group(age male_init)
gegen countynum=group(fipscounty_init)
gegen countyXentrymonth=group(fipscounty_init covstart_month)
****REGRESSION
cap mkdir "$SSDIMed/results/estimates/spending_unempatapp"
local clust countyXentrymonth 
local sample all
local x unemprateatapp
foreach ctrl in "years_since_covstart" "age_sex years_since_covstart"  "countynum age_sex years_since_covstart" "covstart_month countynum age_sex years_since_covstart"{
  reghdfe `y' unemprateatapp, abs(`ctrl') cluster(`clust') 
  sum `y' if e(sample)
  local y_mean_esample `r(mean)'
  local results_stub $SSDIMed/results/estimates/spending_unempatapp/x-`x'_y-`y'_controls-`ctrl'_cluster-`clust'_sample-`sample'
  estimates save "`results_stub'.ster", replace
  regsave using  "`results_stub'.dta", cmdline p ci detail(all) addlabel(y, `y', y_mean_esample, `y_mean_esample', x, ``x'_x', controls, `controls_`ctrl'', sample, `sample', cluster, `clust') replace
}

}

